package com.gjy.nacos.server.repository;

import com.gjy.nacos.server.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-03-08 11:00:50
 */
public interface UserRepository extends JpaRepository<User, Long> {

    @Query(value = "SELECT * FROM USER_TABLE WHERE USER_AGE>:AGE", nativeQuery = true)
    List<User> findUsersGtAge(@Param("AGE") BigDecimal age);

    @Modifying
    @Query(value = "update user_table set user_email=:email where id=:ID",nativeQuery = true)
    Integer updateUserEmailById(@Param("email")String email,@Param("ID") Long id);

    @Modifying
    @Query(value = "delete from user_table where id=:ID", nativeQuery = true)
    Integer deleteUserNatById(@Param("ID") Long id);

    @Modifying
    @Query(value = "insert into user_table(USER_NAME,USER_email,USER_AGE,ID) values(:name,:email,:age,:id)", nativeQuery = true)
    Integer saveUser(@Param("name") String name,@Param("email")String email,@Param("age")BigDecimal age,@Param("id")Long id);

}
